//
//  MLZMapViewController.m
//  MotherLover
//
//  Created by lanou on 16/1/6.
//  Copyright © 2016年 zj. All rights reserved.
//
#define DeviceHeight            [[UIScreen mainScreen] bounds].size.height
#define DeviceWidth             [[UIScreen mainScreen] bounds].size.width

#define Key_DistrictSelectProvince          @"DistrictSelectProvince"
#define Key_DistrictSelectProvinceCode      @"DistrictSelectProvinceCode"
#define Key_DistrictSelectProvinceSubCode   @"DistrictSelectProvinceSubCode"
#define Key_DistrictSelectProvinceSub       @"DistrictSelectProvinceSub"
#define Key_DistrictSelectCityCode          @"DistrictSelectCityCode"
#define Key_DistrictSelectCity              @"DistrictSelectCity"


#import "MLZMapViewController.h"

#import "GPDateView.h"

#import "MLTServiceCategoryCardCollectionViewCell.h"

#import "MLTServiceCategoryCardViewLayout.h"

#import "MLTBusinessesListViewController.h"

#import "MLTBaseMapViewController.h"

#import "MLTSearchMapViewController.h"

@interface MLZMapViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>

// BarButtonItem 右侧按钮
@property (nonatomic, strong) UIBarButtonItem *locationCityButton;

//省份
@property (nonatomic, strong) NSString *province;

//城市
@property (nonatomic, strong) NSString *city;

//城市分区
@property (nonatomic, strong) NSString *area;

@property (nonatomic, strong) MLTServiceCategoryCardViewLayout *layOut;
@property (nonatomic, strong) UICollectionView *collectionView;


//类型数据源数组
@property (nonatomic, strong) NSArray *CategoryArray;

//图片数据源数组
@property (nonatomic, strong) NSArray *pictureArray;

@end

@implementation MLZMapViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    
    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"MapBackPic_4.png"]]];
    
    self.navigationController.navigationBar.hidden= YES;
    
    _province = @"上海市";
    _city = @"上海市";
    _area = @"黄浦区";
    
    
    // 类型数据源数组
    _CategoryArray = @[@"婴儿游泳", @"早教中心", @"幼儿园", @"幼儿外语", @"幼儿才艺", @"幼儿美术", @"小学", @"景点郊游", @"公园", @"博物馆", @"亲子乐园", @"亲子摄影", @"超市/便利店", @"面包甜点", @"西餐"];
    
    //图片数据源数组
    _pictureArray = @[@"Pic_0.png", @"Pic_1.png", @"Pic_2.png", @"Pic_3.png", @"Pic_4.png", @"Pic_5.png", @"Pic_6.png", @"Pic_7.png", @"Pic_8.png", @"Pic_9.png", @"Pic_10.png", @"Pic_11.png", @"Pic_12.png", @"Pic_13.png", @"Pic_14.png"];
    
    
    //添加 CollectionView
    [self addCollectionView];
    
    //调用添加视图方法
    [self addButtonAndLable];
    
}

#pragma mark --- 添加视图方法
- (void)addButtonAndLable
{
    UIButton *rightButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    rightButton.frame = CGRectMake(KW - 130, 30, 100, 60);
    rightButton.layer.cornerRadius = 10;
    rightButton.layer.masksToBounds = YES;
    [rightButton setBackgroundImage:[UIImage imageNamed:@"ChangeCity"] forState:(UIControlStateNormal)];
    [rightButton setTitleColor:[UIColor blueColor] forState:(UIControlStateNormal)];
    [rightButton addTarget:self action:@selector(changeCityButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:rightButton];
}

#pragma mark --- 点击切换城市按钮 弹出 pickView 来切换城市

- (void)changeCityButtonAction:(UIBarButtonItem *)changeCityButton
{
   
//利用 自定义的 GPDateView 类
    
    GPDateView * dateView = [[GPDateView alloc] initWithFrame:CGRectMake(0, DeviceHeight-250, DeviceWidth, 250) Data:nil];
    
    [dateView showPickerView];
    
    dateView.ActionDistrictViewSelectBlock = ^(NSString *desStr,NSDictionary *selectDistrictDict){
        
        //省份
        _province = [selectDistrictDict objectForKey:Key_DistrictSelectProvince];
        
        //城市
        _city = [selectDistrictDict objectForKey:Key_DistrictSelectCity];
        
        //城市区
        _area = [selectDistrictDict objectForKey:Key_DistrictSelectProvinceSub];
        
        //刷新 collectionView
        [self.collectionView reloadData];
        
    };
    
    
}

//添加 CollectionView
- (void)addCollectionView
{
    //自定义的 UICollectionViewFlowLayout
    _layOut = [[MLTServiceCategoryCardViewLayout alloc] init];

    _collectionView = [[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:_layOut];
    
    // collectionView 整也滑动
    _collectionView.pagingEnabled = YES;
    
    _collectionView.backgroundColor = [UIColor clearColor];
    
    
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    
    [self.view addSubview:_collectionView];
    
    [_collectionView registerClass:[MLTServiceCategoryCardCollectionViewCell class] forCellWithReuseIdentifier:@"ServiceCell"];
    
}


#pragma  mark --- 代理方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 1;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return _CategoryArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MLTServiceCategoryCardCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ServiceCell" forIndexPath:indexPath];
    
    cell.nameString = _CategoryArray[indexPath.section];
    cell.picString = _pictureArray[indexPath.section];
    cell.provinceString = _province;
    cell.cityString = _city;
    cell.areaString = _area;
    
    
    return cell;
}


//点击 collectionView 跳转到搜索界面
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

    MLTSearchMapViewController *searchMapVC = [[MLTSearchMapViewController alloc] init];
    
    //传给搜索界面值
    searchMapVC.city = _city;
    searchMapVC.keyWord = _CategoryArray[indexPath.section];
    
    [self.navigationController pushViewController:searchMapVC animated:YES];
    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
